home *** CD-ROM | disk | FTP | other *** search
- Path: news.wyoming.com!usenet
- From: dcromley@wyoming.com (Dave Cromley)
- Newsgroups: comp.lang.c++
- Subject: Re: Help on assignment
- Date: 22 Feb 1996 05:02:28 GMT
- Organization: wyoming.com LLC
- Message-ID: <4ggtd4$hg@horn.wyoming.com>
- NNTP-Posting-Host: cys-cap-10.wyoming.com
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.99.2
-
- >.. Don't think I recieved enough information..
-
- I'm probably not doing you a favor by giving you this,
- but I am learning C++ pretty well from your questions.
- I hope you can get going in your book.
-
- I wonder if 'polymorphism' is the word for subr1--
- having two versions of subr1, depending on the call.
- I also wonder if you could do this in one version and a
- parameter check somehow.
-
- 'Zerosmaller' shows reference parameters. I hope your book
- explains that. In C, you would do 'zerosmaller(&i5, &i7)'
- and the prog would be 'zerosmaller(*i1, *i2) { ..'.
-
- Dave C.
-
- #include <iostream.h>
-
- void subr1(char *s); //subr1 - 1st
- void subr1(char *s, int n); //subr1 - 2nd
- void zerosmaller(int &i1, int &i2); // zerosmaller
-
- void main() {
- subr1("Print this once");
- subr1("Print this three times", 3);
- int i5 = 5, i7 = 7;
- zerosmaller(i5, i7);
- cout << "i5 = " << i5 << ", i7 = " << i7 << endl;
- }
-
- void subr1(char *s) { // subr1 - 1st
- cout << s << endl;
- }
-
- void subr1(char *s, int n) { // subr1 - 2nd
- while (n-- > 0) {
- cout << s << endl;
- }
- }
-
- void zerosmaller(int &i1, int &i2) { // zerosmaller - reference args
- if (i1 < i2) i1 = 0;
- else if (i1 > i2) i2 = 0;
- else {
- i1 = 0; i2 = 0;
- }
- }
-
-
-